package cn.cheneyjoo.controller;

import cn.cheneyjoo.DTO.ResponseDTO;
import cn.cheneyjoo.model.Products;
import cn.cheneyjoo.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/product")
public class ProductsController {
    @Autowired
    private ProductsService productsService;
    /**
     * 获取一个商品信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Products getOneProduct(@PathVariable Integer id) {
        System.out.println(id);
        Products product = productsService.getOneProduct(id);
        return product;
    }
    /**
     * 保存商品信息
     *
     * @param product
     * @return
     */
    @PostMapping()
    public ResponseDTO saveProduct(Products product) {
        boolean b = productsService.saveProduct(product);
        return new ResponseDTO(b ? 200 : 203, b ? "成功" : "失败", null);
    }

}
